Use master
go

If Not Exists( Select name From syslogins
                 Where name = "TryLogin" )
  Exec sp_addlogin TryLogin, "LoginTry", K_DL
go

If Not Exists( Select name From syslogins
                 Where name = "FY2000Login" )
  Exec sp_addlogin FY2000Login, "Login2000FY"
go

If Not Exists( Select name From syslogins
                 Where name = "webuser" )
  Exec sp_addlogin webuser, "R!s2B#w4"
go

If Not Exists( Select name From syslogins
                 Where name = "MaintUser" )
  Exec sp_addlogin MaintUser, "R1@uT#3iA$"
go

Use K_DM
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_DM" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "webuser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias webuser, dbo
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_XS
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_XS" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_MS
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_MS" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_JJ
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_JJ" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_ZC
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_ZC" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_XZ
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_XZ" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_ZX
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_ZX" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_ZS
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_ZS" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_XX
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_XX" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "webuser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias webuser, dbo
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_PTXX
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_PTXX" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "webuser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias webuser, dbo
go


Use K_YS
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_YS" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_TJ
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_TJ" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_WL
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_WL" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_FY
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_FY" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "webuser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias webuser, dbo
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_RW
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_RW" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use K_DL
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_DL" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "TryLogin" ) )
  Exec sp_changedbowner TryLogin
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "TryLogin" ) )
  Exec sp_addalias FY2000Login, dbo
go
If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "TryLogin" ) )
  Exec sp_addalias MaintUser, dbo
go

Use dynamo
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "dynamo" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "webuser" ) )
  Exec sp_changedbowner webuser
go

Use K_KH
go
If Not Exists( Select name From master..sysdatabases
                 Where name = "K_KH" And
                       suid = ( Select suid From master..syslogins
                                  Where name = "FY2000Login" ) )
  Exec sp_changedbowner FY2000Login
go

If Not Exists( Select suid From sysalternates
                 Where suid = ( Select suid From master..syslogins
                                  Where name = "MaintUser" ) And
                       altsuid = ( Select suid From master..syslogins
                                     Where name = "FY2000Login" ) )
  Exec sp_addalias MaintUser, dbo
go

Use master
go
